package com.situ.feemanagement.controller;

import com.situ.feemanagement.pojo.entity.Patient;
import com.situ.feemanagement.pojo.query.PatientQuery;
import com.situ.feemanagement.service.IPatientService;
import com.situ.feemanagement.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/patient")
public class PatientController {

    @Autowired
    private IPatientService patientService;

    @GetMapping("/selectAll")
    public Result selectAll() {
        List<Patient> list = patientService.selectAll();
        return Result.ok(list);
    }

    @GetMapping("/list")
    public Result list(PatientQuery patientQuery) {
        Map<String, Object> map = patientService.selectByPage(patientQuery);
        return Result.ok(map);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        patientService.deleteById(id);
        return Result.ok("删除成功");
    }

    @DeleteMapping("/deleteAll/{ids}")
    public Result deleteAll(@PathVariable Integer[] ids) {
        patientService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @PostMapping("/add")
    public Result add(@RequestBody Patient patient) {
        patientService.add(patient);
        return Result.ok("添加成功");
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Patient patient = patientService.selectById(id);
        return Result.ok(patient);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Patient patient) {
        patientService.update(patient);
        return Result.ok("更新成功");
    }
}
